package org.aceor.mddal.common.sqlparser.util;

import com.google.common.base.Strings;

/**
 * Created by lxue on 16/4/6.
 */
public class SQLCommonUtil {
    public static final String SELECT = "select";
    public static final String UPDATE = "udpate";

    public static boolean isQuerySql(String sql) {
        if (Strings.isNullOrEmpty(sql)) {
            throw new IllegalArgumentException();
        }
        if (sql.toLowerCase().contains(SELECT) && !sql.toLowerCase().contains(UPDATE)) {
            return true;
        } else if (!sql.toLowerCase().contains(SELECT) && sql.toLowerCase().contains(UPDATE)) {
            return false;
        } else {
            throw new IllegalArgumentException("sql :" + sql + " 有误,无法确定是查询还是更新语句");
        }
    }
}
